using AI.Graph;
using UnityEngine;

[CreateNodeMenu ("Condition/In Range")]
public class InRangeCondition : Condition {

    [ParameterType (typeof (GameObject))]
    public NodeParameter targetGameObjectParameter;

    public float range;

    private GameObject target;


    protected override bool OnDecide (AIBehaviour aiBehaviour) {
        if (aiBehaviour.TryGetValue (targetGameObjectParameter, out target)) {
            return (target.transform.position - aiBehaviour.transform.position).sqrMagnitude <= range * range;
        }

        Debug.Log ("No target set.");
        return false;
    }

}